/*
 * @Description: IBE信息化平台
 * @Author: IBE
 * @Date: 2020-05-14 14:25:43
 * @LastEditTime: 2023-07-26 16:34:08
 * @LastEditors: yang
 */
import Vue from 'vue'
import microApps from './micro-app'
import 'normalize.css/normalize.css' // A modern alternative to CSS resets
import { registerMicroApps, start, setDefaultMountApp } from 'qiankun'

console.log('microApps---->', microApps)

// 虚拟滚动
import VueVirtualScroller from 'vue-virtual-scroller'
Vue.use(VueVirtualScroller)
import 'vue-virtual-scroller/dist/vue-virtual-scroller.css'

// 配置信息
import config from '@/config'
window.WKConfig = config
Vue.prototype.WKConfig = config

import { getPermissionByKey } from './utils'
Vue.prototype.$auth = getPermissionByKey

import i18n from '@/i18n/i18n'
import { getLangContent, setI18nLanguage, getSatisfactionLang } from '@/i18n/utils'
Vue.prototype.$getLangContent = getLangContent
Vue.prototype.$getSatisfactionLang = getSatisfactionLang
// 初始化相关库的语言
setI18nLanguage(i18n.locale)
// 金额单位设置
import { getMoneyUnit, getMoneyUnitValue } from './utils'
Vue.prototype.$unit = getMoneyUnit
Vue.prototype.$money = getMoneyUnitValue

import ElementUI from 'element-ui'
ElementUI.Tag.props.disableTransitions = {
  type: Boolean,
  default: true
}
Vue.use(ElementUI)
import { Message } from 'element-ui'
const message = function (data) {
  if (!data.hasOwnProperty('duration')) {
    data.duration = 1500
  }
  return Message(data)
}
const messageTyps = ['success', 'warning', 'info', 'error']
messageTyps.forEach(type => {
  const duration = 1500
  message[type] = data => {
    return Message({
      message: data,
      type,
      duration
    })
  }
})
Vue.prototype.$message = message

import 'element-ui/lib/theme-chalk/index.css'
import 'el-bigdata-table'

import Vue2OrgTree from 'vue2-org-tree'
import 'vue2-org-tree/dist/style.css'
Vue.use(Vue2OrgTree)

import '@/styles/index.scss' // global css

import App from './App'
import router from './router'
import store from './store'

import cache from '@/utils/cache'
cache.loadingCache()

import '@/permission' // permission control
import 'vue2-animate/dist/vue2-animate.min.css'

/** 事件传递 */
import VueBus from 'vue-bus'
Vue.use(VueBus)

/** 常用flex组件 */
import { Flexbox, FlexboxItem } from '@/components/Flexbox'
Vue.component('Flexbox', Flexbox)
Vue.component('FlexboxItem', FlexboxItem)

Vue.config.productionTip = false

registerMicroApps(microApps, {
  beforeLoad: app => {
    console.log('加载主应用之前 %c%s', 'color:blue;', app.name)
  },
  beforeMount: [
    app => {
      console.log('主应用挂载前 %c%s', 'color:red;', app.name)
    }
  ],
  afterMount: [
    app => {
      console.log('主应用挂载后 %c%s', 'color: blue;', app.name)
    }
  ],
  afterUnmount: [
    app => {
      console.log('主应用卸载前 %c%s', 'color: blue;', app.name)
    }
  ]
})
setDefaultMountApp('/oa-front')
const options = {
  // 是否预加载
  prefetch: false,
  // 是否开启沙箱样式隔离
  sandbox: true,
  // 是否为单实例场景，单实例指的是同一时间只会渲染一个微应用。默认为 true。
  singular: true
}
start(options)

window.app = new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App)
})
